package models

import (
	"doctor-srv/basic/config"
	"gorm.io/gorm"
)

// 患者表
type Patient struct {
	gorm.Model
	Name     string `json:"name" gorm:"type:varchar(30);comment:'姓名'"`
	Password string `json:"password" gorm:"type:varchar(32);comment:'密码'"`
	Age      int    `json:"age" gorm:"type:int;comment:'年龄'"`
	Sex      string `json:"sex" gorm:"type:varchar(3);comment:'性别'"`
	Address  string `json:"address" gorm:"type:varchar(100);comment:'地址'"`
	CardId   string `json:"card_id" gorm:"type:varchar(18);comment:'身份证号码'"`
}

func (p *Patient) TableName() string {
	return "patient"
}

func (p *Patient) AddPatient() error {
	return config.DB.Create(&p).Error
}

func (p *Patient) GetPatientInfo(cardId string) error {
	return config.DB.Model(&Patient{}).Where(":card_id = ?", cardId).Limit(1).Find(&p).Error
}

func (p *Patient) GetPatient(id int) error {
	return config.DB.Model(&Patient{}).Where("id = ?", id).Limit(1).Find(&p).Error
}
